<template>
  <div>
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in showList" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <el-row type="flex" justify="end">
      <el-button type="primary" @click="hSubmit">确定</el-button>
      <el-button @click="close">取消</el-button>
    </el-row>
  </div>
</template>
<script>
import { getRoles, getUserDetailById, importAssignRoles } from '@/api/employees'
export default {
  name: '',
  props: {
    allotId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      checkList: [],
      showList: [],
      q: {
        page: 1,
        pagesize: 100
      }
    }
  },
  computed: {
  },
  created() {
    this.initRolesList()
  },
  methods: {
    async initRolesList() {
      try {
        const { data } = await getUserDetailById(this.allotId)
        this.checkList = data.roleIds
        const res = await getRoles(this.q)
        this.showList = res.data.rows
      } catch (err) {
        return err
      }
    },
    // 下单
    async hSubmit() {
      try {
        await importAssignRoles({ id: this.allotId, roleIds: this.checkList })
        this.$message.success('给用户分配角色成功')
        this.close()
      } catch (err) {
        return err
      }
    },
    close() {
      this.$emit('allotClose')
    }
  }
}
</script>
<style lang='less'  scoped>

</style>
